<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <div id="app"></div>
  
  <script src="../react-js/react.development.js" crossorigin></script>
  <script src="../react-js/react-dom.development.js" crossorigin></script>
  <script src="../react-js/babel.min.js"></script>

  <script type="text/babel">
    // jsx的本质
    // jsx -> createElement函数 -> ReactElement(对象树) -> ReactDOM.render -> 真实DOM
    // jsx -> createElement函数 -> ReactElement(对象树) -> ReactDOM.render -> 原生的控件(UIButton/Button)
    class App extends React.Component {
      constructor() {
        super()

        this.state = {
          isLogin: false
        }
      }

      render() {
        const { isLogin } = this.state
        
        //每此按钮点击会重新调用render() 生成新的这个常量 所以这里修改没毛病
        const eleDisplayValue = isLogin ? 'block' : 'none'

        let welcome = null
        if(isLogin) {
          welcome = <h2>欢迎回来！</h2>
        }else {
          welcome = <h2>请先登录~</h2>
        }
        
        return (
          <div>
            { welcome }

            <button onClick={ () => this.handlerBtnClick() }>{ isLogin ? '退出' : '登录' }</button>

            { isLogin && <h2>是false就不存在dom</h2> }

            <h2 style={ {display: eleDisplayValue} }>元素的display</h2>
          </div>
        )
      }

      handlerBtnClick() {
        this.setState({
          isLogin: !this.state.isLogin
        })
      }
    }

    ReactDOM.render(<App/>, document.getElementById('app'))
  </script>
  
</body>
</html>